package com.sykj.why.controller.front.home;

import com.sykj.why.exception.WhyException;
import com.sykj.why.handler.Response;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import com.sykj.why.mongo.service.AlbumTService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Eleven
 * @date 2019/6/21
 * @desc 首页访问控制层
 */

@RestController
@RequestMapping("/front/home")
@Slf4j
@Api(value = "/front/home",description = "首页访问控制层")
public class HomeController {

    @Autowired
    private AlbumTService albumTService;

    /**
     * 获取首页数据
     * @param programaId
     * @return
     */
    @RequestMapping(value = "/getData",method = RequestMethod.GET)
    @ApiOperation(value = "/getData",notes = "获取首页数据")
    public ResponseEntity getData(@RequestParam String programaId,@RequestParam int count){
        try {
            return Response.success("查询成功", albumTService.homeData(programaId,count));
        } catch (WhyException e) {
            return Response.serverError(e.getMessage(), e.getCode());
        } catch (Exception e) {
            log.error("查询首页数据出现异常，{}", e.getMessage());
            return Response.serverError(ResultEnum.UNERROR.getMessage(), ResultEnum.UNERROR.getCode());
        }
    }

}
